<!-- <template>
  <panel title="添加账号">
    <el-form label-width="100px" :model="addInfo" :rules="rules" ref="addInfo">
      <el-form-item label="账号" prop="account">
        <el-input type="text" placeholder="请输入账号" v-model="addInfo.account"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="text" placeholder="请输入密码" v-model="addInfo.password"></el-input>
      </el-form-item>
      <el-form-item label="用户组" prop="userGroup">
        <el-select v-model="addInfo.userGroup" placeholder="请选择用户组">
          <el-option value="超级管理员" label="超级管理员"></el-option>
          <el-option value="普通管理员" label="普通管理员"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">确认</el-button>
        <el-button @click="resetForm('addInfo')">重置</el-button>
      </el-form-item>
    </el-form>
  </panel>
</template>

<script>
// import axios from "@/utils/requests";
import { userAccAdd } from '@/api/account.api'
export default {
  data() {
    const validateAcc = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入账号！！"));
      } else {
        callback();
      }
    };
    const validatePwd = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码！！"));
      } else {
        callback();
      }
    };
    return {
      value: "",
      addInfo: {
        account: "",
        password: "",
        userGroup: "",
      },
      rules: {
        account: [{ required: true, validator: validateAcc, trigger: "blur" }],
        password: [{ required: true, validator: validatePwd, trigger: "blur" }],
        userGroup: [{ required: true, message: "请选择用户组！！" }],
      },
    };
  },
  methods: {
    add() {
      console.log(this.addInfo);
      this.$refs.addInfo.validate(async (res) => {
        if (res) {
          const res = await userAccAdd(this.addInfo);
          if (res.data.code === 0) {
            this.$message({
              message: res.data.msg,
              type: "success",
            });
            this.$router.push("/account/list");
          }
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="less" scoped>
.remove {
  /deep/ .el-form-item__label:before {
    display: none;
  }
}

.el-input {
  width: 300px;
}
</style> -->


<template>
  <panel title="添加账号">
    <AccountForm type="adds" @success="success"></AccountForm>
  </panel>
</template>

<script>
import Panel from '@/panel/Panel.vue';
import AccountForm from './components/AccountForm.vue';
import { userAccAdd } from '@/api/account.api'

export default {
  components: { Panel, AccountForm },
  methods: {
    success(addInfo) {
      userAccAdd(addInfo).then(res => {
        if (res.data.code == 0) {
          this.$message({
            message: res.data.msg,
            type: "success",
          });
          this.$router.push("/account/list");
        }
      })
    }
  }

}
</script>

<style lang="less" scoped>

</style>